from selenium.webdriver.common.by import By
import time
from common.Utils import TestDriver
import datetime
from selenium.webdriver.common.keys import Keys

class Editor:
    url = ""
    driver = ""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-in.html"
        self.driver = TestDriver.driver
        self.driver.get(self.url)

    #测试帖子编辑页面

    def EditorSection(self):
        self.driver.implicitly_wait(3)
        #登录
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("lisi")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        actual1 = self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert actual1 == "首页"
        #进入帖子编辑页面
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
    #
    #     self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad")
    #     self.driver.find_element(By.CSS_SELECTOR,"#username")
    #     self.driver.find_element(By.CSS_SELECTOR,"#username")

    def EditorSucPost(self):
        self.driver.implicitly_wait(3)
        title =   "TestSuc" + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys(title)
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(21) > a > i").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        actual = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div.jq-toast-single.jq-has-icon.jq-icon-success > h2").text
        assert actual == "成功"

    def EditorFailPost(self):
        self.driver.implicitly_wait(3)
        time.sleep(4)
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #不写标题
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(21) > a > i").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        actual1 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        actual1 = "提示"
        time.sleep(4)
        #不写内容
        self.driver.refresh()
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        title ="TestFail" + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys(title)
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        actual2 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        actual2 = "提示"






editor = Editor()
editor.EditorSection()
editor.EditorSucPost()
editor.EditorFailPost()






















